﻿using System;
using System.Diagnostics;

namespace Union_Find
{
    class Program
    {
        static void Main(string[] args)
        {
            var tinyData = new UFData("tinyUF.txt");
            var mediumData = new UFData("mediumUF.txt");
            var largeData = new UFData("largeUF.txt");

            TestUF(tinyData, UFVersion.V1);
            TestUF(mediumData, UFVersion.V1);
            //TestUF(largeData, UFVersion.V1);

            TestUF(tinyData, UFVersion.V2);
            TestUF(mediumData, UFVersion.V2);
            //TestUF(largeData, UFVersion.V2);

            TestUF(tinyData, UFVersion.V3);
            TestUF(mediumData, UFVersion.V3);
            TestUF(largeData, UFVersion.V3);

            TestUF(tinyData, UFVersion.V4);
            TestUF(mediumData, UFVersion.V4);
            TestUF(largeData, UFVersion.V4);
        }

        static void TestUF(UFData ufdata, UFVersion version)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();

            var uf = UFFactory.GetUF(ufdata, version);
            foreach (var connection in ufdata.Connections)
            {
                if (uf.Connected(connection[0], connection[1])) continue;
                uf.Union(connection[0], connection[1]);

                //Console.WriteLine($"{connection[0]} {connection[1]}");
            }
            Console.WriteLine($"{version}: {uf.Count} Components");

            sw.Stop();
            TimeSpan ts = sw.Elapsed;
            Console.WriteLine($"总共耗时{ts.TotalMilliseconds}毫秒.");
        }
    }

}
